package com.example.curd.controller;


import com.example.curd.common.ResponseHelper;
import com.example.curd.common.ResponseModel;
import com.example.curd.payload.request.User.AddUserRequest;
import com.example.curd.payload.request.User.DeleteUserRequest;
import com.example.curd.payload.request.User.SelectUserRequest;
import com.example.curd.payload.request.User.UpdateUserRequest;
import com.example.curd.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dakai
 * @since 2021-04-18
 */
@Api(tags = "用户信息")
@RestController
@RequestMapping(value = "/user")
public class UserController {
  @Resource
  private IUserService iuserService;

  @ApiOperation("查询用户")
  @PostMapping("/selectUser")
  public ResponseModel selectUser(@RequestBody SelectUserRequest request) {
    return ResponseHelper.buildResponseModel(iuserService.selectUser(request));
  }

  @ApiOperation("添加用户")
  @PostMapping("/addUser")
  public ResponseModel addUser(@RequestBody AddUserRequest request) {
    iuserService.addUser(request);
    return ResponseHelper.buildResponseModel("添加成功");
  }

  @ApiOperation("修改用户")
  @PostMapping("/updateUser")
  public ResponseModel updateUser(@RequestBody UpdateUserRequest request) {
    iuserService.updateUser(request);
    return ResponseHelper.buildResponseModel("修改成功");
  }
  @ApiOperation("删除用户")
  @PostMapping("/deleteUser")
  public ResponseModel deleteUser(@RequestBody DeleteUserRequest request) {
    iuserService.deleteUser(request);
    return ResponseHelper.buildResponseModel("删除成功");
  }
}
